<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="/common/template :: header(~{::title},~{::link},~{::style})"></head>
<style>
    .setmaealInput{
        width: 80%!important;
    }

    .input-group {
        position: relative;
        display: table;
        border-collapse: separate;
        width: 100%;
    }
    .input-group .form-control, .input-group-addon {
        display: table-cell;
    }
    .input-group-addon {
        padding: 5px;
        text-align: center;
        background-color: #eee;
        border-radius: 2px;
        border-top-left-radius: 0;
        border-bottom-left-radius: 0;
    }
    .input-group .form-control:first-child{
        border-top-right-radius: 0;
        border-bottom-right-radius: 0;
    }
</style>
<script type="text/javascript" src="/js/wangEditor.js"></script>
<body>
    <input id="shopId" th:value="${shops.shopId}" type="hidden">
    <!--  -->
    <div class="layui-form-item" >
        <div id="shopDetails"></div>
    </div>

    <div class="layui-form-item" style="display: flex;justify-content: center;">
        <button id="submit"  class="layui-btn" >立即提交</button>
    </div>

    <p th:text="${shops.shopDetails}" id="data" hidden></p>
<script th:replace="/common/template :: script"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    layui.use([ 'layer', 'jquery', 'form', 'laydate' ], function() {
        var $ = layui.jquery;

        //日期时间选择器

        //富文本编辑器
        const E = window.wangEditor
        const editor = new E('#shopDetails')
        editor.config.width = 400
        // 或者 const editor = new E(document.getElementById('div1'))
        // 配置 server 接口地址
        editor.config.uploadImgServer = '/editorUploadImg'
        editor.create()
        var shopDetails = $("#data").text();

        editor.txt.html(shopDetails ? shopDetails : '')


        //提交

        //提交事件
        $("#submit").click(function () {
            var shopdata = {};
            shopdata.shopId = $("#shopId").val();

            shopdata.shopDetails = encodeURIComponent(editor.txt.html());

            //将图片添加到fromdata
            //图片不为空才能提交if(flag){}
            $.ajax({
                url: "/shopsService/shops/saveShopDetails",
                data: shopdata,
                type: "Post",
                //cache: false,上传文件无需缓存
                success: function (data) {
                    if(data.code==200){
                        layer.msg(data.msg);
                        parent.window.location.href="/shopsService/shops/index?msg="+data.msg;
                    }else {
                        layer.msg(data.msg,{time:1500});
                    }
                }
            })


        })

    });
</script>
</body>
</html>